Home:ALL Converter>How do I read application properties in Micronaut?

How do I read application properties in Micronaut?

Ask Time:2018-11-23T01:55:41         Author:Aditya T

Json Formatter

I integrated AWS SES API to my Micronaut Groovy application using guide send mail in micronaut and I am able send mails if I directly assign values to properties.

I want to make it config driven hence have been trying to find ways to achieve that.

I tried @Value annotation as mentioned in guide but was not able to make it work.

@Value("aws.secretkeyid")
String keyId

Further digging into documentation revealed that Micronaut has its own annotation for injecting properties in variables.

@Property(name="aws.secretkeyid")
String keyId

But nothing seems to work, my variables are still null.

What could be possibly wrong here ?

For reference, following is in my application.yml file

aws:
  keyid: "2weadasdwda"
  secretkeyid: "abcdesdasdsddddd"
  region: "us-east-1"

Author:Aditya T,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53436144/how-do-i-read-application-properties-in-micronaut
Álvaro Sánchez-Mariscal :

You are using it incorrectly, you are injecting the literal value aws.secretkeyid, not the value of a variable.\n\nThe correct syntax is (Groovy):\n\n@Value('${aws.secretkeyid}')\nString keyId\n\n\nNotice that you must use single quotes to avoid Groovy to attempt interpolation\n\nJava:\n\n@Value(\"${aws.secretkeyid}\")\nString keyId;\n\n\nKotlin:\n\n@Value(\"\\${aws.secretkeyid}\")\nkeyId: String\n\n\nNotice that you must use a backslash to escape the dollar sign to avoid Kotlin string templates",
2018-11-23T10:54:06
yy